package aoj.no_0500;

import java.util.HashMap;
import java.util.Scanner;

public class No_0501 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int nData = sc.nextInt();
			if(nData == 0)
				break;
			
			HashMap<Character, Character> map = new HashMap<Character, Character>();
			int count = 0;
			while(count < nData) {
				map.put(sc.next().charAt(0), sc.next().charAt(0));
				count++;
			}
			
			int nInput = sc.nextInt();
			count = 0;
			while(count < nInput) {
				char c = sc.next().charAt(0);
				if(map.containsKey(c)) {
					System.out.print(map.get(c));
				}
				else {
					System.out.print(c);
				}
				count++;
			}
		System.out.flush();
		System.out.println();
		}
	}
}
/*
3	
A a	
0 5	
5 4	
10	
A	
B	
C	
0	
1	
4	
5	
a	
b	
A
3	
A a	
0 5	
5 4	
10	
A	
B	
C	
0	
1	
4	
5	
a	
b	
A
0 
 */
